package com.zk.atm.utils;

import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.TreeMap;

import org.apache.log4j.Logger;

public class InitDeviceStatusConfig {

		public static final Logger logger=Logger.getLogger(AccessDBConnection.class);

		static {
			Properties prop = new Properties();
			InputStream in = AccessDBConnection.class.getResourceAsStream("/dbconfig.properties");
			try {
				prop.load(in);
			} catch (IOException e) {
				e.printStackTrace();
			}
//			sys_db = prop.getProperty("JDBC.").toLowerCase();
		}
		//根据文件路径,加载配置文件的内容
		public static Map<String,String> getConfigProperties(Map argsMap){
			Map<String,String> configMap=new TreeMap<String,String>();
			try {
				String file_path=StringUtil.getPropertyValue(argsMap.get("file_path"));
				if(file_path.equals("")){
					String msg="文件路径为空,不能执行初始化加载,请与管理员联系!";
					logger.error(msg);
					System.out.println(logger);
					return null;
				}
				Properties prop = new Properties();
				InputStream in = AccessDBConnection.class.getResourceAsStream("/"+file_path+"");
				try {
					prop.load(in);
				    Enumeration enumer=prop.propertyNames();
			        while(enumer.hasMoreElements()){
				    	String key=StringUtil.getPropertyValue(enumer.nextElement());
				    	String value=prop.getProperty(key);
				    	if(logger.isDebugEnabled()){
				    		System.out.println("************InitDeviceStatusConfig:getConfigProperties:key="+key+",value="+value);
				    	}
				    	configMap.put(key, value);
			        }
				} catch (IOException e) {
					e.printStackTrace();
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			return configMap;
		}
		
		/**
		 * @author zengqun
		 * @remark 获取设备监控最大监控停报时间
		 * @date 2012-10-31
		 * @param argsMap
		 * @return
		 * @throws Exception
		 */
		public static Map<String,String> getDeviceStatusConfigMap(Map<String,String> argsMap) throws Exception{
			if(argsMap==null){
				argsMap=new TreeMap<String,String>();
			}
			Map<String,String> status_map=new TreeMap<String,String>();
			argsMap.put("file_path", "device_status.properties");
			status_map=InitDeviceStatusConfig.getConfigProperties(argsMap);
			return status_map;
		}
		
		public static void main(String[] args) {
          Map<String,String> argsMap=new HashMap<String,String>();
		argsMap.put("file_path","export_trade.properties");
          //argsMap.put("file_path", "device_status.properties");
	     try {
				//InitDeviceStatusConfig.getDeviceStatusConfigMap(argsMap);
	    	 InitDeviceStatusConfig.getConfigProperties(argsMap);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

	
}
